let db = require('./sqlite.js')

class QianKaDBController {
  constructor(tableName) {
    this.db = new db.SqliteDB('./db/qianka');
    this.tableName = tableName;
  }
  create() {
    let sql = `CREATE TABLE ${this.tableName}(
      ID INTEGER PRIMARY KEY AUTOINCREMENT,
      sendName           TEXT    NOT NULL,
      appName            TEXT    NOT NULL,
      appSrc             TEXT    NOT NULL,
      isSend             TEXT
    )`
    console.log(sql)
    this.db.createTable(sql)
  }

  insert(data) {
    let sql = ` INSERT INTO ${this.tableName} (sendName,appName,appSrc,isSend)
                VALUES ( ?,?,?,?);`
    console.log(sql)
    console.log(data)
    this.db.insertData(sql, [data])
  }

  query() {
    let sql = ` select * from ${this.tableName}`
    console.log(sql)
    this.db.queryData(sql, res => {
      console.log(res)
    })
  }
  executeSql(sql) {
    this.db.executeSql(sql)
  }
}

module.exports = QianKaDBController


// let qk = new QianKaDBController('qianka0');
// qk.create();
// qk.inster(['夕阳', '淘宝淘宝淘宝', 'http://1232.com',0])
// qk.query()
// let sql = `update ${qk.tableName} set isSend=0`
// console.log(sql)
// qk.executeSql(sql)
// qk.query()
